cmake_minimum_required(VERSION 3.0)

project(showmem)

set(CMAKE_C_COMPILER "ntoaarch64-gcc")
set(CMAKE_CXX_COMPILER"ntoaarch64-g++")

include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/include
    ${CMAKE_CURRENT_SOURCE_DIR}/.
)

set(SOURCE_SHOWMEM
    ${CMAKE_CURRENT_SOURCE_DIR}/displaymem.c
    ${CMAKE_CURRENT_SOURCE_DIR}/extractmaps.c
    ${CMAKE_CURRENT_SOURCE_DIR}/extractstats.c
    ${CMAKE_CURRENT_SOURCE_DIR}/showmem.c
)

add_executable(showmem ${SOURCE_SHOWMEM})

# Add usemsg to showmem
set(BACKTRACE_USEMSG
    ${CMAKE_CURRENT_SOURCE_DIR}/showmem.use
)

add_custom_target(use_showmem ALL
                COMMAND usemsg ${CMAKE_CURRENT_SOURCE_DIR}/showmem ${BACKTRACE_USEMSG}
                COMMENT "Build usemsg for backtrace"
                DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/showmem
                DEPENDS ${BACKTRACE_USEMSG}
)
add_dependencies(use_showmem showmem)

set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/out/aarch64" CACHE PATH "Installation prefix" FORCE)
install(TARGETS showmem DESTINATION bin)